<template>
	<view class="upgrad">
		<view class="upgrad_box">
			<template v-if="dev.length > 0">
				<view class="upgrad_box_li dont_upgrad my-mgt-15 my-pdl-15" v-for="(item,index) in dev" :key="index">
					<view class="upgrad_box_li_num">
						<text class="zifu">￥</text>
						<text class="money">{{item.price||0}}</text>
					</view>
					<view class="upgrad_box_li_center">
						<view class="upgrad_box_li_center_name my-pdl-25">商品优惠券</view>
						<view class="upgrad_box_li_center_time my-mgt-5 my-pdl-25">领取时间：{{item.createDate.substring(0,10) || '暂无'}}</view>
					</view>
					<view class="upgrad_box_bg">
						<view class="upgrad_box_bg_btn" :class="item.used?'upgrad_gray':'upgrad_red'" @click="gouse">{{item.used?'已使用':'去使用'}}</view>
					</view>
				</view>
			</template>
			<view style="line-height: 300rpx;text-align: center;" v-else>暂无数据</view>
		</view>
	</view>
</template>

<script>
	import { getcouponsApi} from "@/api/myinter.js"
	export default {
		data() {
			return {
				pageIndex: 0,
				pageSize: 30,
				total:1,
				dev:[],
			};
		},
		onLoad() {
			this.getcoupons()
		},
		// 上拉加载更多
		onReachBottom() {
			this.getcoupons()
		},
		methods:{
			async getcoupons(){
				if(this.dev.length >= this.total){
					uni.showToast({
						title:"没有更多数据了!",
						icon:"none"
					})
					return 
				}
				let params = {
					pageIndex:this.pageIndex,
					pageSize:this.pageSize
				}
				uni.showLoading({
					title:"正在加载中...."
				})
				const res= await getcouponsApi(params)
				if(res.statusCode === 200){
					uni.hideLoading()
					res.data.data.rows.forEach(item=>this.dev.push(item))
					this.total = res.data.data.total
					this.pageIndex++
				}
			},
			gouse(){
				uni.navigateTo({
					url:"/pages/main/homePages"
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.upgrad{
		width: 100%;
		height:100vh;
		background: #FAFAFA;
		.upgrad_box{
			width: 100%;
			min-height: 200rpx;
			.upgrad_box_li{
				width: 660rpx;
				height: 168rpx;
				margin: auto;
				display: flex;
				align-items: center;
				.upgrad_box_li_num{
					width: 27%;
					font-weight: bold;
					color: #F05329;
					.zifu{
						font-size: 32rpx;
					}
					.money{
						font-size: 70rpx;
					}
				}
				.upgrad_box_li_center{
					width: 55%;
					.upgrad_box_li_center_name{
						font-size: 32rpx;
						font-weight: bold;
						color: #4E4142;
					}
					.upgrad_box_li_center_time{
						font-size: 22rpx;
						font-weight: 500;
						color: #654C4C;
					}
				}
				.upgrad_box_bg{
					width: 24%;
					.upgrad_box_bg_btn{
						width: 120rpx;
						height: 55rpx;
						line-height: 55rpx;
						text-align: center;
						border-radius: 28px;
						border-radius: 28rpx;
						font-size: 26rpx;
						font-weight: 500;
						color: #FFFFFF;
					}
					.upgrad_red{
						background: #F05329;
						
					}
					.upgrad_gray{
						background: #B3B1B1;
						
					}
				}
			}
			.dont_upgrad{
				background-image: url(https://hxc-pay.oss-cn-shenzhen.aliyuncs.com/TCOLJRPUAX_dont_use.png);
			}
			.in_upgrad{
				background-image: url(https://hxc-pay.oss-cn-shenzhen.aliyuncs.com/VmjiuIoOoC_in_use.png);
			}
		}
	}
</style>
